package com.fadadianqi.logistics.admin.printer;

import com.fadadianqi.commons.ConfigHelper;
import com.yeqiangwei.commons.util.ParamUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

@Controller
public class PrintTesterController {

    @RequestMapping(value = "/a/print/tester", method = RequestMethod.GET)
    public String showList(HttpServletRequest request, ModelMap modelMap) {

        return "printTest";
    }

    @RequestMapping(value = "/a/print/tester", method = RequestMethod.POST)
    public String print(HttpServletRequest request, ModelMap modelMap) throws Exception {
        String billId = ParamUtils.getString(request, "billId", "1367710169390");
        //billPrinter.doPrint(billId);


        String ip = ConfigHelper.getString("printer.ip");
        EthernetPrinter printer = new EthernetPrinter(ip, 9100);
        printer.printBarCode(billId);
        printer.finish();

        modelMap.put("command", "print...");
        return "printTest";
    }

    @Autowired
    private BillPrinter billPrinter;
}
